package com.wj.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.wj.api.UserApi;
import com.wj.entity.User;
import com.wj.entity.UserDto;
import com.wj.repository.UserRepository;
import com.wj.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author jun.wang
 * @title: UserServiceImpl
 * @projectName ownerpro
 * @description: TODO
 * @date 2019/9/26 15:16
 */

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserRepository userRepository;

    @Autowired
    private UserApi userApi;

    @Override
    @LcnTransaction
    @Transactional
    public int addUser(UserDto userDto) {
        User user = new User();
        BeanUtils.copyProperties(userDto, user);
        userRepository.save(user);

        List<JSONObject> list = userApi.findMenuByRole(1);
        Map<String, Object> map = new HashMap<>();
        map.put("roleId", 1);
        map.put("menuInfoVoList", list);
        userApi.addRoleMenu(map);
        return 0;
    }
}
